<template>
  <el-dialog
    title="编辑"
    :visible.sync="visible"
    :show-close="false"
    width="800px"
    :modal="true"
    :close-on-click-modal="false"
    :close-on-press-escape="false"
  >
    <button type="button" aria-label="Close" class="el-dialog__headerbtn" @click.stop="cancelModal">
      <i class="el-dialog__close el-icon el-icon-close"></i>
    </button>
    <el-form
      class="form-wrapper"
      ref="orderForm"
      :model="orderForm"
      :rules="addRules"
      label-width="110px"
    >
      <el-row>
        <el-col :span="12">
          <el-form-item label="代码：" prop="code">
            <el-input
              style="width:180px;"
              :disabled="true"
              v-model="orderForm.code"
              type="text"
              placeholder="请输入代码"
            ></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="名称：" prop="name">
            <el-input style="width:180px;" v-model="orderForm.name" type="text" placeholder="请输入名称"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="12">
          <el-form-item label="默认：" prop="checkboxvalue">
            <el-checkbox v-model="checkboxvalue"></el-checkbox>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="状态：" prop="status">
            <el-select
              :disabled="true"
              style="width:180px;"
              v-model="orderForm.status"
              placeholder="请选择"
            >
              <el-option label="停用" value="2"></el-option>
              <el-option label="启用" value="1"></el-option>
            </el-select>
          </el-form-item>
        </el-col>
      </el-row>
      <div style="margin:10px;">其他信息</div>
      <el-row>
          <el-col :span="12">
            <el-form-item label="创建人：">
                <el-input style="width:180px;" v-model="orderForm.zdr" type="text" :disabled="true"></el-input>
            </el-form-item>
           </el-col>
          <el-col :span="12">
            <el-form-item label="创建时间：">
                <el-input style="width:180px;" v-model="orderForm.zdrq" type="text" :disabled="true"></el-input>
            </el-form-item>
          </el-col>
      </el-row>
      <el-row>
          <el-col :span="12">
            <el-form-item label="修改人：">
                <el-input style="width:180px;" v-model="orderForm.xgr" type="text" :disabled="true"></el-input>
            </el-form-item>
           </el-col>
          <el-col :span="12">
            <el-form-item label="修改时间：">
                <el-input style="width:180px;" v-model="orderForm.xgrq" type="text" :disabled="true"></el-input>
            </el-form-item>
          </el-col>
      </el-row>
      <el-row>
          <el-col :span="12">
            <el-form-item label="启用人：">
                <el-input style="width:180px;" v-model="orderForm.qyr" type="text" :disabled="true"></el-input>
            </el-form-item>
           </el-col>
          <el-col :span="12">
            <el-form-item label="启用时间：">
                <el-input style="width:180px;" v-model="orderForm.qyrq" type="text" :disabled="true"></el-input>
            </el-form-item>
          </el-col>
      </el-row>
      <el-row>
          <el-col :span="12">
            <el-form-item label="停用人：">
                <el-input style="width:180px;" v-model="orderForm.tyr" type="text" :disabled="true"></el-input>
            </el-form-item>
           </el-col>
          <el-col :span="12">
            <el-form-item label="停用时间：">
                <el-input style="width:180px;" v-model="orderForm.tyrq" type="text" :disabled="true"></el-input>
            </el-form-item>
          </el-col>
      </el-row>
    </el-form>
    <div slot="footer" class="buttons-wrap">
      <el-button type="primary" @click="submitForm('orderForm')">保存</el-button>
    </div>
  </el-dialog>
</template>
<script>
export default {
  props: {
    visible: {
      type: Boolean,
      default: false
    },
    editdata: {
      type: Object
    }
  },
  data() {
    return {
      user: JSON.parse(window.sessionStorage.getItem("user")),
      checkboxvalue: this.editdata.xtmr == "1" ? true : false,
      orderForm: JSON.parse(JSON.stringify(this.editdata)),
      addRules: {
        code: [{ required: true, message: "请输入代码", trigger: "blur" }],
        name: [{ required: true, message: "请输入名称", trigger: "blur" }]
      }
    };
  },
  methods: {
    initForm() {
      this.orderForm = {
        code: "",
        name: "",
        xtmr: "",
        status: "1",
        zdr: "",
        qyr: ""
      };
      if (this.$refs.orderForm) {
        this.$refs.orderForm.resetFields();
      }
    },
    submitForm(formName) {
      this.$refs[formName].validate(valid => {
        if (valid) {
          console.log(this.orderForm);
          //  确定时 对值进行转换
          // this.orderForm.zdr =
          if (this.checkboxvalue) {
            this.orderForm.xtmr = 1;
          } else {
            this.orderForm.xtmr = 0;
          }
          this.orderForm.xgr = this.user.name;
          this.postRequest("/earnestmoney/sklx/update", this.orderForm).then(
            res => {
              console.log(res, "11111");
              if (res.status == "200") {
                this.$parent.getdata();
                this.$emit("update:visible", false);
              }
            }
          );
        } else {
          console.log("error submit!!");
          return false;
        }
      });
    },
    cancelModal() {
      // 关闭弹窗，触发父组件修改visible值
      this.$emit("update:visible", false);
    }
  }
};
</script>
<style lang="scss" scoped>
.buttons-wrap {
  .el-button {
    margin-right: 20px;
    min-width: 100px;
  }
}
</style>